/**
 * Copyright (c) 2011 Roundarch (www.roundarch.com)
 *
 * Author Joshua Jung
 *
 * ---
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.roundarch.flex.controls.graphControlClasses
{
    import com.roundarch.flex.controls.GraphControlBase;
    import com.roundarch.flex.controls.graphControlInterfaces.IGraphControlChild;
    import com.roundarch.flex.controls.graphControlInterfaces.IInterval;
    import com.roundarch.flex.controls.graphControlInterfaces.IIntervalCollection;
    import com.roundarch.flex.controls.intervals.Interval;
    import flash.events.Event;
    import flash.events.EventDispatcher;

    /**
     * @author jjung
     */
    public class GraphControlAxisOptions extends EventDispatcher
    {
        //---------------------------------------------------------------------
        //
        //  Variables
        //
        //---------------------------------------------------------------------
        /**
         * When true, all display objects are snapped to the pixel when calculated from values.
         *
         * @default true
         */
        public var snapToPixel : Boolean = true;

        public var intervalCollection : IIntervalCollection;

        /**
         * If labelFunction is specified, then getValueAsString uses that function instead
         * of itself.
         *
         * @default null
         */
        public var labelFunction : Function = null;

        [ArrayElementType("com.roundarch.flex.controls.graphControlInterfaces.IIntervalCollection")]
        /**
         * An array of intervals that are disabled.
         */
        public var disabledRanges : Array;

        //---------------------------------------------------------------------
        //
        //  Properties
        //
        //---------------------------------------------------------------------
        //-----------------------------
        // minmax
        //-----------------------------
        protected var _minMax : IInterval = new Interval(Number.MIN_VALUE, Number.MAX_VALUE);

        [Bindable("minMaxChanged")]
        /**
         * The maximum value of this axis.
         *
         * @default 10
         */
        public function get minMax() : IInterval
        {
            return _minMax;
        }

        /**
         * @private
         */
        public function set minMax(value : IInterval) : void
        {
            if (value == _minMax)
            {
                return;
            }

            _minMax = value;

            if (_minMax)
            {
                _minMax.bind(this, "visibleMinMaxChanged");
            }

            dispatchEvent(new Event("minMaxChanged"));
        }

        //-----------------------------
        // visibleMinMax
        //-----------------------------
        /**
         * @private
         */
        protected var _visibleMinMax : IInterval = new Interval(Number.MIN_VALUE, Number.MAX_VALUE);

        [Bindable("visibleMinMaxChanged")]
        /**
         * The maximum value of this axis.
         *
         * @default 10
         */
        public function get visibleMinMax() : IInterval
        {
            return _visibleMinMax;
        }

        /**
         * @private
         */
        public function set visibleMinMax(value : IInterval) : void
        {
            if (value == _visibleMinMax)
            {
                return;
            }

            _visibleMinMax = value;

            if (_visibleMinMax)
            {
                _visibleMinMax.bind(this, "visibleMinMaxChanged");
            }

            dispatchEvent(new Event("visibleMinMaxChanged"));
        }


        //---------------------------------------------------------------------
        //
        //  Constructor
        //
        //---------------------------------------------------------------------
        /**
         *  Constructor
         */
        public function GraphControlAxisOptions()
        {
            super();
        }

        //---------------------------------------------------------------------
        //
        //  Methods
        //
        //---------------------------------------------------------------------
        /**
         * Returns the value as a String.
         */
        public function getValueAsString(value : Number) : String
        {
            if (labelFunction != null)
            {
                return labelFunction(value);
            }

            return value.toString();
        }
    }
}
